package com.tianwen.management.controller;

import com.tianwen.management.entity.Employee;
import com.tianwen.management.result.Result;
import com.tianwen.management.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: personnel-management
 * @description
 * @author: tianwen
 * @create: 2023-05-17 09:04
 **/
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    @GetMapping("/page/{page}/{pageSize}")
    public Result page(@PathVariable Integer page,@PathVariable Integer pageSize,String name){
        List<Employee> employeeList=employeeService.page(page, pageSize, name);
        return Result.ok().data("employeeList",employeeList);
    }
    @PostMapping("/add")
    @PreAuthorize("hasAuthority('员工增删改')")
    public Result add(@RequestBody Employee employee){
        employeeService.save(employee);
        return Result.ok();
    }
    @GetMapping("/delete")
    @PreAuthorize("hasAuthority('员工增删改')")
    public Result delete(@RequestParam Long id){
        employeeService.removeById(id);
        return Result.ok();
    }
    @PostMapping("/update")
    @PreAuthorize("hasAuthority('员工增删改')")
    public Result update(@RequestBody Employee employee){
        employeeService.save(employee);
        return Result.ok();
    }
}
